package com.heo.thread;

import org.apache.log4j.Logger;

import com.heo.coder.packet.base.BasePacket;
import com.heo.server.NettyServerSocketHandler;
import com.heo.util.NettyChannelMapUtils;

public class SendMessageSocketThread implements Runnable {

	private static Logger logger = Logger.getLogger(SendMessageSocketThread.class);

	private BasePacket packet;
	private int sleep = 100;
	private NettyServerSocketHandler nettyServerSocketHandler = null;

	public SendMessageSocketThread(String appId, String deviceImei, BasePacket packet, int sleep) {
		this.nettyServerSocketHandler = NettyChannelMapUtils.get(appId, deviceImei);
		this.packet = packet;
		this.sleep = sleep;
	}

	@Override
	public void run() {
		try {
			if (nettyServerSocketHandler != null) {
				if(sleep > 0) {
					Thread.sleep(sleep);
				}
				nettyServerSocketHandler.sendMessage(packet);
			}
		} catch (Exception e) {
			logger.info("SendMessageTransparentThread Exception = " + e.getMessage());
		}
	}
}
